import { Entity, PrimaryGeneratedColumn, Column, CreateDateColumn, UpdateDateColumn, ManyToMany } from 'typeorm';
import { Role } from './role.entity';

export enum PermissionGroup {
  SYSTEM = 'system',       // 系统管理
  USER = 'user',          // 用户管理
  PROJECT = 'project',    // 项目管理
  TASK = 'task',         // 任务管理
  WORKSPACE = 'workspace' // 工作区管理
}

@Entity('permissions')
export class Permission {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({ unique: true })
  name: string;

  @Column({ unique: true })
  code: string;

  @Column({ nullable: true })
  description: string;

  @Column({
    type: 'enum',
    enum: PermissionGroup,
    default: PermissionGroup.SYSTEM
  })
  group: PermissionGroup;

  @ManyToMany(() => Role, role => role.permissions)
  roles: Role[];

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
} 